<style>

</style>
<div class="layui-layout order-wrapper" style="padding:0 20px;">
    <div class="layui-row">
        <div class="layui-col-md4 layui-col-md-offset1">
            <table class="layui-table">
                <thead>
                <tr>
                    <th style="text-align: center">充值订单总数</th>
                    <th style="text-align: center">普通充值订单</th>
                    <th style="text-align: center">VIP充值订单</th>
                </tr>
                </thead>
                <tbody>
                <tr align="center">
                    <td>{{.total}}</td>
                    <td>{{.common}}</td>
                    <td>{{.vip}}</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="layui-col-md4 layui-col-md-offset2">
            <table class="layui-table">
                <thead>
                <tr>
                    <th style="text-align: center">今日</th>
                    <th style="text-align: center">本周</th>
                    <th style="text-align: center">本月</th>
                    <th style="text-align: center">总交易</th>
                </tr>
                </thead>
                <tbody>
                <tr align="center">
                    <td>{{.dayProfit}}</td>
                    <td>{{.weekProfit}}</td>
                    <td>{{.monthProfit}}</td>
                    <td>{{.totalProfit}}</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div id="search-wrapper">
        <div class="layui-form">
            <div class="layui-row">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" id="start_time" name="start_time"  placeholder="请输入开始时间（支付）" class="layui-input">
                    </div> 至
                    <div class="layui-input-inline">
                        <input type="text" id="end_time" name="start_time"  placeholder="请输入结束时间（支付）" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <select name="app" class="app" lay-verify="">
                        <option value="-1">请选择用户来源</option>
                        {{range $index, $elem := .app}}
                            <option value="{{$elem.Id}}">{{$elem.AppName}}</option>
                        {{end}}
                    </select>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn search" data-type="reload">搜索</button>
                </div>
                <div class="layui-inline fr">
                    <button class="layui-btn layui-btn-normal export">导出</button>
                </div>
            </div>
        </div>
    </div>
    <table class="layui-hide" id="table_list" lay-filter="table_filter">
    </table>
</div>
<script>
    layui.use(['table','laydate','form'], function(){
        var table = layui.table;
        var $ = layui.$;
        //方法级渲染
        table.render({
            elem: '#table_list'
            ,url: '/order/table'
            ,where: {appId:$('.app').val()}
            ,cols: [[
                {field:'Sort', title: '序号', align:'center',width:'100',fixed:'left'},
                {field:'UserId', title: '用户Id', align:'center',width:'120',fixed:'left'},
                {field:'Nickname', title: '用户名', align:'center',width:'150',fixed:'left'},
                {field:'AppName', title: '用户来源', align:'center',width:'150'},
                {field:'Type', title: '订单类型', align:'center',width:'120',templet:function (d) {
                        if(d.Type == 1){
                            return "普通充值"
                        }else{
                            return "VIP充值"
                        }
                    }},
                {field:'Name', title: '商品名称', align:'center',width:'120'},
                {field:'Desc', title: '商品描述', align:'center',width:'150'},
                {field:'Price', title: '商品价格（元）', align:'center',width:'150',templet:function (d) {
                        return d.Price/100;
                    }},
                {field:'PayType', title: '支付方式', align:'center',width:'120',templet:function (d) {
                        if(d.PayType == 0){
                            return "微信"
                        }else{
                            return "支付宝"
                        }
                    }},
                {field:'Status', title: '订单状态', align:'center',width:'120',templet:function (d) {
                        if(d.Status == 1){
                            return "成功"
                        }else{
                            return "失败"
                        }
                    }},
                {field:'ApplyDate', title: '订单产生时间', align:'center',width:'180',templet:function (d) {
                        return (d.ApplyDate + '').split("+")[0].replace("T"," ")
                    }},
                {field:'CommitDate', title: '订单支付时间', align:'center',width:'180',templet:function (d) {
                        return (d.CommitDate + '').split("+")[0].replace("T"," ")
                    }},
                {field:'OrderId', title: '订单编号', align:'center',width:'320'},
                {field:'TransactionId', title: '第三方编码', align:'center',width:'320'},
            ]]
            ,id: 'listReload'
            ,page: {
                curr: location.hash.replace('#!fenye=', '') //获取起始页
                ,hash: 'fenye' //自定义hash值
            }
            ,height: "full-200"
        });

        var active = {
            reload: function(){
                table.reload('listReload', {
                    where: {
                        startTime:$("#start_time").val(),
                        endTime:$("#end_time").val(),
                        appId:$(".app").val()
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            }
        };


        var laydate = layui.laydate;
        var endDate= laydate.render({
            elem: '#end_time',//选择器结束时间
            type: 'datetime',
            min:"1970-1-1",//设置min默认最小值
            done: function(value,date){
                startDate.config.max={
                    year:date.year,
                    month:date.month-1,//关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                }
            }
        });
        //日期范围
        var startDate=laydate.render({
            elem: '#start_time',
            type: 'datetime',
            max:"2099-12-31",//设置一个默认最大值
            done: function(value, date){
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1, //关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                };
            }
        });

        $('#search-wrapper .search').on('click', function(){
            if($("#start_time").val() == '' && $("#end_time").val() != ''){
                layer.msg("请将时间补充完整");
                return
            }
            if($("#start_time").val() != '' && $("#end_time").val() == ''){
                layer.msg("请将时间补充完整");
                return
            }
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';

        });

        $(".export").click(function(){
            var urlParam = "?page=1&limit=99999&startTime="+$('#start_time').val() + '&endTime=' + $('#end_time').val()+ '&appId=' + $('.app').val() + "&export=1";
            window.open('/order/table'+urlParam)
        });

    })



</script>